@extends('admin.layout')
@section('body')
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表格工具栏 -->
                <form class="layui-form toolbar" id="formSearch">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">科室:</label>
                            <div class="layui-input-inline">
                                <x-ca.top-disease name="department_id" show-all="--请选择科室--" id="sltTopDisease"
                                                  lay-filter="topDisease"></x-ca.top-disease>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">疾病:</label>
                            <div class="layui-input-inline">
                                <select class="layui-input" name="disease_id" id="sltDisease">

                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">所属省份:</label>
                            <div class="layui-input-inline">
                                <x-system.province show-all="--请选择省份--" id="sltProvince" name="province_id"
                                                   lay-filter="province"></x-system.province>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">所在市区:</label>
                            <div class="layui-input-inline">
                                <select class="layui-input" id="sltCity" name="city_id">

                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">日期范围:</label>
                            <div class="layui-input-inline">
                                <input name="date_range" autocomplete="off" id="txtDateRange" class="layui-input"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">关键词:</label>
                            <div class="layui-input-inline">
                                <input name="keyword" class="layui-input"
                                       placeholder="@lang('job.article.keyword_placeholder')"/>
                            </div>
                        </div>
                        <div class="layui-inline">&emsp;
                            <button class="layui-btn icon-btn" lay-filter="searchForm" lay-submit>
                                <i class="iconfont icon-ic_search"></i>@lang('common.search')
                            </button>
                        </div>
                    </div>
                </form>
                <!-- 数据表格 -->
                <table id="adminTable" lay-filter="adminTable"></table>
            </div>
        </div>
    </div>
@stop
@push('script')
    <script type="text/javascript">
        layui.use(['layer', 'form', 'table', 'util', 'admin', 'laydate'], function () {
            layui.laydate.render({
                elem: '#txtDateRange'
                , range: '~' //或 range: '~' 来自定义分割字符
            });
            layui.form.on('select(province)', function (item) {
                loadCity(item.value);
            });

            layui.form.on('select(topDisease)', function (item) {
                loadDisease(item.value);
            });
            function loadDisease(value) {
                if (value) {
                    SystemUtil.ajax("{{admin_url('ca/disease/load')}}", "GET")
                        .setData({pid: value})
                        .send(1)
                        .done(function (res) {
                            let html = "<option value='0'>--请选择疾病--</option>";
                            res.data.forEach(function (item) {
                                html += `<option value='${item.id}'>${item.name}</option>`;
                            });
                            layui.$('#sltDisease').html(html);
                            layui.form.render("select");
                        });
                } else {
                    let html = "<option value='0'>--请选择疾病--</option>";
                    layui.$('#sltDisease').html(html);
                    layui.form.render("select");
                }
            }

            function loadCity(value) {
                if (value > 0) {
                    SystemUtil.ajax("{{admin_url('system/area/load')}}", "GET")
                        .setData({pid: value})
                        .send(1)
                        .done(function (res) {
                            let html = "<option value='0'>--请选择城市--</option>";
                            res.data.forEach(function (item) {
                                html += `<option value='${item.id}'>${item.name}</option>`;
                            });
                            layui.$('#sltCity').html(html);
                            layui.form.render("select");
                        });
                } else {
                    let html = "<option value='0'>--请选择城市-</option>";
                    layui.$('#sltCity').html(html);
                    layui.form.render("select");
                }
            }

            let listTableInc = new ListTable("{{admin_url($baseRoute.'pager')}}");
            {{--            @auth('show','ca/customer')--}}
            {{--            listTableInc.showBar((tb, d) => {--}}
            {{--                SystemUtil.openUrl2({--}}
            {{--                    title: "@lang('common.edit')",--}}
            {{--                    content: "{{admin_url($baseRoute.'edit')}}/" + d.id,--}}
            {{--                    area: ['400px', '280px']--}}
            {{--                });--}}
            {{--                SystemUtil.CurrentTableInc = tb;--}}
            {{--            });--}}
            {{--            @endauth--}}

            @auth('annotate')
            listTableInc.actionBar('<button type="button" class="layui-btn layui-btn-xs">批注</button>', (tb, d) => {
                SystemUtil.openUrl2({
                    title: "@lang('common.edit')",
                    content: "{{admin_url($baseRoute.'annotate')}}/" + d.id,
                    area: ['400px', '280px']
                });
                SystemUtil.CurrentTableInc = tb;
            });
            @endauth
            listTableInc.lineNumber();
            listTableInc.column("回访时间", "created_at").setWithDateTime();
            listTableInc.column("患者", "name");
            listTableInc.column("疾病", "diseases");
            listTableInc.column("内容", "content");
            listTableInc.column("批注", "supervisor_annotate");
            listTableInc.column("区域", "area_name");
            listTableInc.column("咨询", "user_name");
            listTableInc.column("下次回访时间", "next_time");
            listTableInc.rowBarWidth = 70;
            listTableInc.render();
            window.listTableInc = listTableInc;
        });
    </script>
@endpush
